package com.aclever.resouces;


import com.aclever.sys.modules.ProxyAuth;

import java.io.IOException;
import java.io.InputStream;
import java.net.Proxy;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

/**
 *
 * Sitebean - класс который представяет объект "САЙТ"
 *
 */


public class Sitebean {
    private int responseCode = 0;
    private String responseMessage = "--";
    private final String HTTP_PROTOCOL = "http";
    private final String DEFAULT_SITE_PATH = "";
    private URL siteURL;


    public Sitebean(String sitename) throws MalformedURLException {
        siteURL = new URL(HTTP_PROTOCOL, sitename, DEFAULT_SITE_PATH);
    }

    public Sitebean(String sitename, String sitepath) throws MalformedURLException {
        siteURL = new URL(HTTP_PROTOCOL, sitename, sitepath);
    }

    public Sitebean(String protocol, String sitename, String sitepath) throws MalformedURLException {
        siteURL = new URL(protocol, sitename, sitepath);
    }



    public String getSiteHost(){
        return siteURL.getHost();
    }

    public synchronized int getSiteResponseCode(){
        HttpURLConnection siteConnect;
            try {
                siteConnect = (HttpURLConnection) siteURL.openConnection();
                responseCode = siteConnect.getResponseCode();

            } catch (IOException e) {
                System.out.println("IOException when you openConnection");
                responseCode = -1;
            }

        return responseCode;
    }


    public synchronized String getSiteResponseMessage(){
        try {
            HttpURLConnection siteConnect = (HttpURLConnection) siteURL.openConnection();
            responseMessage = siteConnect.getResponseMessage();
        } catch (IOException e) {
            System.out.println("IOException when you openConnection");
            responseMessage = "X";
        }
        return responseMessage;
    }

}
